﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class defaultLayout : System.Web.UI.MasterPage
{
    public Translator tl;

    private account user;

    protected void Page_Init(object sender, EventArgs e)
    {
        if (Session["db"] == null)
        {
            Session["db"] = new debioscoopEntities();
        }

        debioscoopEntities db = (debioscoopEntities)Session["db"];

        user = (Session["user"] != null) ? (account)Session["user"] : null;

        if (Session["Translator"] != null)
        {
            tl = (Translator)Session["Translator"];
            currentLanguage.Value = (tl.getCurrentLanguage());
        }
        else
        {
            tl = new Translator();
            tl.setLanguage("dutch");
            Session["Translator"] = tl;
            currentLanguage.Value = "dutch";
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        tl.pageTranslator(mainForm.Controls);

        hlAccount.NavigateUrl = (user != null) ? ("~/Account.aspx") : ("~/Login.aspx");
        hlAccount.Text = (user != null) ? user.gebruikersnaam : tl.getTranslation("loginOrRegister");

        hlLogout.Visible = ( user != null )? true : false;
        hlLogout.Text = tl.getTranslation("logout");
        hlLogout.NavigateUrl = Page.ResolveClientUrl("~/Login.aspx?logout=true");

        lblSep.Visible = (user != null) ? true : false;
    }

    protected void language_Click(object sender, EventArgs e)
    {
        tl.setLanguage((currentLanguage.Value.Equals("dutch") ? "english" : "dutch"));
        Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri);
    }

    public account getUser()
    {
        return user;
    }
}
